/*  Copyright © 2009 Blake Hegerle -*- C++ -*- */

/*  This file is part of metal.
 
    Metal is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see
    <http://www.gnu.org/licenses/>.

*/

#include "identifier.h"
#include "module.h"
#include "drivers/idriver.h"
#include "drivers/llvm_driver.h"
#include "drivers/llvm_program.h"
#include "io.h"

#include <iostream>
#include <cassert>

using namespace metal;
using namespace metal::driver;

namespace {
  ident(a);
  ident(b);
  ident(c);
  ident(get);
  ident(f);
  ident(i);
  ident(g);
  ident(h);
}

#define mod(x, ...) auto x = ( module<>(#x), __VA_ARGS__);

void map_tests() {
  std::cout << "map_tests" << std::endl;

  mod(map_mod, 

      get = def(param(int *, a), param(int, b)) ( a[b] )
      
      , f = def() ( map(a * 2, a *= array(1, 2, 3)) )

      , g = def(param(int, i)) ( f()[i] )

      , h = def() ( eval(a + b,
				c = array(3, 5),
				a = get(c, 0),
				b = get(c, 1)
				) 
			   )

      );

  auto d = llvm_driver();
  map_mod.emit(d);
  d.dump();

  auto p = link(map_mod);

  auto mapped0 = p.call(f)();
  auto mapped1 = p.call(h)();
}
